﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Collections;

namespace NetTookKits.IOCP
{
    class SocketAsyncEventArgsPool
    {
        #region datamembers
        private Stack<AsyncSocketClient> _pool;
        private int _capacity;
        #endregion
        #region constructor
        public SocketAsyncEventArgsPool(int initCapacity)
        {
            this._capacity = initCapacity;
            _pool = new Stack<AsyncSocketClient>(_capacity);
        }
        #endregion
        #region methods
        public AsyncSocketClient Pop()
        {
            lock (_pool)
            {
                if (_pool.Count > 0)
                    return _pool.Pop();
                else
                    return null;
            }
        }
        public void Push(AsyncSocketClient ayncSocketClient)
        {
            if (ayncSocketClient == null)
            {
                throw new ArgumentException("Items added to a AsyncSocketUserToken cannot be null");
            }
            lock (_pool)
            {
                _pool.Push(ayncSocketClient);
            }
        }
        #endregion
    }
}
